package com.base.sweb.js;

import android.app.Activity;
import android.content.Context;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.base.BaseApp;
import com.base.commonlib.bean.UpdateScopeStatEntity;
import com.base.commonlib.event.StudyEvent;
import com.base.commonlib.sp.SpUtil;
import com.base.commonlib.utils.RxBus2;
import com.base.commonlib.utils.ToastUtil;
import com.base.sweb.manage.SuperWebX5;


/**
 * describe：公共加载fragment类
 *
 * @author ：鲁宇峰 on 2018/8/8 13：44
 * email：luyufengc@enn.cn
 */
public class AndroidInterface extends Object {


    private SuperWebX5 superWeb;
    private Context context;
    private Activity activity;
    private WebView webView;

    public AndroidInterface(SuperWebX5 superWeb, Context context) {
        this.superWeb = superWeb;
        this.context = context;
    }

    public AndroidInterface(SuperWebX5 superWeb, Activity context) {
        this.superWeb = superWeb;
        this.activity = context;
    }

    public AndroidInterface(WebView webView, Activity context) {
        this.webView = webView;
        this.activity = context;
    }

    @JavascriptInterface
    public void callAndroidTestPaper() {
        ARouter.getInstance().build("/case/case2add")
                .withString("ID", "0f2274b4a1bb4074a79305a43547561a")
                .withInt("num", 1)
                .withString("type", "5")
                .withBoolean("isCase", true)
                .withString("isSimulate", "1")
                .navigation();
    }

    @JavascriptInterface
    public String callAndroidGetToken() {
        return SpUtil.getToken();
    }

    @JavascriptInterface
    public void callAndroidBack() {
        activity.finish();
    }

    @JavascriptInterface
    public void callAndroidSubject() {
        ARouter.getInstance().build("/sublect/list")
                .navigation();
    }

    @JavascriptInterface
    public void callAndroidTestDetail() {
        ARouter.getInstance().build("/case/case2add")
                .withString("ID", "02c51755117d4b0c8724319229f62542")
                .withInt("num", 1)
                .withString("type", "5")
                .withBoolean("isCase", true)
                .withString("isSimulate", "1")
                .navigation();
    }

    @JavascriptInterface
    public void callAndroidExaminationl() {
        ARouter.getInstance().build("/sublect/list")
                .navigation();
    }

    @JavascriptInterface
    public void clickImage(String s) {
        //ToastUtil.show("点击图片  "+s);
    }

    @JavascriptInterface
    public void callAndroidToStudy() {
        RxBus2.getInstance().post(new StudyEvent(2));
        ARouter.getInstance().build("/study/home")
                .navigation();
    }


    /**
     * 跳转动态新闻
     */
    @JavascriptInterface
    public void callAndroidToDynamicNews() {
        ARouter.getInstance().build("/subject/formsubject")
                .withString("firstCategoryName", "垃圾分类新时尚")
                .withString("secondCategoryName", "动态新闻")
                .withString("id", "d2bfb1f84918495abb1e52e2185fbe1e")
                .navigation();

    }

    /**
     * 音视频课堂
     */
    @JavascriptInterface
    public void callAndroidToDideo() {
        ARouter.getInstance().build("/subject/formsubject")
                .withString("firstCategoryName", "垃圾分类新时尚")
                .withString("secondCategoryName", "音视频课堂")
                .withString("id","518a02b6279d48c4be32a129be1bb18a")
                .navigation();
    }

    /**
     * 政策法规课堂
     */
    @JavascriptInterface
    public void callAndroidTClassroom() {
        ARouter.getInstance().build("/subject/formsubject")
                .withString("firstCategoryName", "垃圾分类新时尚")
                .withString("secondCategoryName", "政策法规课堂")
                .withString("id","e5405ef33c82470a99b47d489e29f9d9")
                .navigation();
    }


    @JavascriptInterface
    public String callAndroidGetDepartId() {
        return BaseApp.getUser().getDeptId();
    }

    @JavascriptInterface
    public String callAndroidGetUserId() {
        return BaseApp.getUser().getTenantId();
    }

    @JavascriptInterface
    public String callAndroidGetDepertId() {
        return BaseApp.getUser().getDeptId();
    }

    /***
     * 刷新积分
     */
    @JavascriptInterface
    public void callAndroidRefreshScope() {
        RxBus2.getInstance().post(new UpdateScopeStatEntity(1));
    }
}
